package com.mico.example.springboot.redis.controller;

import com.mico.example.springboot.redis.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by micocube
 * ProjectName: springboot-example
 * PackageName: com.mico.example.springboot.redis.controller
 * User: micocube
 * Email: ldscube@gmail.com
 * CreateTime: 2019/2/27下午4:35
 * ModifyTime: 2019/2/27下午4:35
 * Version: 0.1
 * Description:
 **/
@RestController
public class UserController {
    @Autowired
    private RedisTemplate<String,User> redisTemplate;
    @GetMapping("/add")
    public String add(){
        redisTemplate.opsForValue().set("user",new User("root","abc"));
        return "success";
    }

    @GetMapping("/get")
    public User get(){
        User user = redisTemplate.opsForValue().get("user");
        return user;
    }
}
